package com.example.jurisdiction.Controller;

import java.text.SimpleDateFormat;
import java.util.List;

import com.example.jurisdiction.Service.UserService;
import entity.sys_user_info;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


@CrossOrigin(methods = {RequestMethod.POST,RequestMethod.GET})
@RestController
@RequestMapping("/user")
public class UserContoller {
	
	@Autowired
	private UserService userService;

	@Autowired
	BCryptPasswordEncoder bCryptPasswordEncoder;

	@RequestMapping("/login.do")
	public sys_user_info login(sys_user_info s)throws Exception{

		return this.userService.login(s);
	}

//	����û�
	@ResponseBody
	@RequestMapping("/addUser.do")
	public int add(@RequestBody sys_user_info u) throws Exception {

		u.setUserPwd(bCryptPasswordEncoder.encode(u.getUserPwd()));

		return this.userService.addUser(u);
	}
//	ɾ���û�
	@ResponseBody
	@RequestMapping("/delUser.do")
	public int del(Integer id) throws Exception {
			
		return this.userService.delUser(id);
	}
//���ݱ�Ż�ȡָ���û�
	@RequestMapping("/getUser.do")
	public @ResponseBody sys_user_info get(Integer id) throws Exception{
		return this.userService.getUser(id);
	}
//	�޸��û�
	@ResponseBody
	@RequestMapping("/updateUser.do")
	public int updateUser(@RequestBody sys_user_info u)throws Exception{
		System.out.println("联系地址"+u.getAddress());
		System.out.println("bedemobilizedTime"+u.getBedemobilizedTime());
		System.out.println("角色ID"+u.getBirthday());
		System.out.println("角色ID"+u.getDepartmentId());
		System.out.println("角色ID"+u.getEdu());
		System.out.println("角色ID"+u.getEmail());
		System.out.println("角色ID"+u.getJobNumber());
		System.out.println("角色ID"+u.getJobState());
		System.out.println("角色ID"+u.getMountguardTime());
		System.out.println("角色ID"+u.getRemarks());
		System.out.println("角色ID"+u.getSex());
		System.out.println("角色ID"+u.getTelephone());
		System.out.println("角色ID"+u.getUserAccount());
		System.out.println("角色ID"+u.getUserName());
		System.out.println("角色ID"+u.getJobLevalId());
		System.out.println("角色ID"+u.getUserPwd());
		System.out.println("角色ID"+u.getUserId());
		return this.userService.updateUser(u);
		
	}
	
	//��������ģ����ѯ
		@RequestMapping("/select.do")
		public @ResponseBody List<sys_user_info> select(String name) throws Exception{
			return this.userService.select(name);
		}

	@RequestMapping("/getSysUser.do")
	public @ResponseBody List<sys_user_info> getUser() throws Exception{
		return this.userService.getSysUser();
	}
	
}
